package com.handinhand.mobile;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.handinhand.mobile.exception.HandInHandException;
import com.handinhand.mobile.model.Community;
import com.handinhand.mobile.service.CommunityService;

public class CommunitiesActivity extends BaseActivity {
	
	private ListView communitiesLV;
	private ArrayList<Community> communities;
	private HandInHandApplication app;
	private CommunityService communityService;
	private Button createCommunityNavButton;	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_communities);		
		app = getApp();
		communityService = new CommunityService(app);
		/*
		try {
			communities = communityService.getCommunities(getApp().getLoggedUser().getId());
		} catch (HandInHandException e) {			
			e.printStackTrace();
			System.out.println("getCommunities does not work!");
		}
		*/
		setupUI();
	}
	
	private void setupUI() {
		//communitiesLV = (ListView) findViewById(R.id.lvCommunities);
		//ArrayAdapter<Community> adapter = new ArrayAdapter<Community>(this, android.R.layout.simple_list_item_1, communities);
		
		//communitiesLV.setAdapter(adapter);
		createCommunityNavButton = (Button) findViewById(R.id.btnCreateCommunityNav);
		createCommunityNavButton.setOnClickListener(oncreateCommunityNavButtonClick);
	}
	
	private OnClickListener oncreateCommunityNavButtonClick = new OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent intent = new Intent(CommunitiesActivity.this, CreateCommunityActivity.class);
			startActivity(intent);
			finish();
		}
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.communities, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
